package cn.wolfcode.ws;


import org.bouncycastle.pqc.crypto.newhope.NHOtherInfoGenerator;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.concurrent.ConcurrentHashMap;

@Component
@ServerEndpoint("/{token}")
public class OrderWsServer {
    private Session session;
    public static ConcurrentHashMap<String, Session> clients = new ConcurrentHashMap<>();
    @OnOpen
    public void onOpen(Session session, @PathParam( "token") String token){
        System.out.println("客户端连接===>"+token);
        clients.put(token,session);
    }
    @OnMessage
    public  void getMsg(@PathParam("token")String token, String msg){
        System.out.println("收到客户端标识为:"+token+"，内容:"+msg);
    }
    @OnClose
    public void onClose(@PathParam( "token") String token){
        System.out.println("客户端断开连接===>"+token);
        clients.remove(token);
    }
    @OnError
    public void onError(Throwable error) {
        error.printStackTrace();
    }

}
